var express = require('express');
var app = express();
var fs = require("fs");

var path=require("path")
//浏览器   http://127.0.0.1:8081/1
// 返回  {"name":"mahesh","password":"password1","profession":"teacher","id":1}
app.get('/:id', function (req, res) {
    // 首先我们读取已存在的用户
    fs.readFile( __dirname + path.sep + "users.json", 'utf8', function (err, data) {
        data = JSON.parse( data );
        var user = data["user" + req.params.id]
        console.log( user );
        res.setHeader('Content-Type', 'text/html; charset=utf8');
        res.end( JSON.stringify(user));
    });
})

var server = app.listen(8081, function () {

    var host = server.address().address
    var port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host, port)

})